<template>
	<view class="content padding">
		<view class="head padding shadow">
			<text class="personal">个人信息</text>
			<view class="info flex flex-direction justify-between" style="height: 122rpx;">
				<text>姓名</text>
				<view class="flex align-center  info_o response padding-lr">
					<input type="text" v-model="payInfo.fullName" placeholder="请输入姓名" />
				</view>
			</view>
			<view class="info flex flex-direction justify-between" style="height: 122rpx;">
				<text>联系方式</text>
				<view class="flex align-center  info_o response padding-lr">
					<input type="number" v-model="payInfo.contactDetails" placeholder="请输入联系方式" />
				</view>
			</view>
		</view>
		<view class="head padding shadow margin-top">
			<text class="personal">居民信息</text>
			<view class="info flex flex-direction justify-between" style="height: 122rpx;">
				<text>楼栋</text>
				<view class="flex align-center  info_o response padding-lr">
					<input type="text" v-model="payInfo.floor" placeholder="请选择楼栋" />
				</view>
			</view>
			<view class="info flex flex-direction justify-between" style="height: 122rpx;">
				<text>单元</text>
				<view class="flex align-center  info_o response padding-lr">
					<input type="text" v-model="payInfo.unit" placeholder="请选择单元号" />
				</view>
			</view>

			<view class="info flex flex-direction justify-between" style="height: 122rpx;">
				<text>楼层门牌号</text>
				<view class="flex align-center  info_o response padding-lr">
					<input type="text" v-model="payInfo.houseNumber" placeholder="请输入楼层门牌号(数字)" />
				</view>
			</view>

			<view class="info flex flex-direction justify-between" style="height: 122rpx;">
				<text>缴费金额</text>
				<view class="flex align-center  info_o response padding-lr">
					<input type="number" v-model="payInfo.paymentAmount" placeholder="请输入缴费金额" />
				</view>
			</view>

			<view class="info flex flex-direction justify-between" style="height: 122rpx;" @click="click">
				<text>缴费月份</text>
				<view class="flex align-center  info_o response padding-lr">
					<input type="text" disabled v-model="payInfo.paymentTime" placeholder="请选择缴费月份" />
				</view>
			</view>

			<view class="info flex flex-direction justify-between" style="height: 122rpx;" @click="options">
				<text>支付方式</text>
				<view class="flex align-center  info_o response padding-lr">
					<input type="text" disabled v-model="payment" placeholder="请选择支付方式" />
				</view>
			</view>

			<u-picker v-model="show" mode="time" @confirm="confirm" :params="params"></u-picker>
			<u-action-sheet :list="list" v-model="showw" @click="chooseToPay"></u-action-sheet>
			<!-- <view class="info flex flex-direction justify-between" style="height: 122rpx;">
				<text>缴费结束时间 </text>
				<view class="flex align-center  info_o response padding-lr">
					<input type="text" value=""  placeholder="请选择缴费结束时间"/>
				</view>
			</view> -->
		</view>
		<button class="cu-btn determine" @click="pay()">确认{{ payment }}</button>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
const app = getApp();
export default {
	data() {
		return {
			show: false,
			payInfo: {
				fullName: '',
				contactDetails: '',
				floor: '',
				unit: '',
				houseNumber: '',
				paymentAmount: '',
				paymentTime: '',
				porpertyId: '',
				payment: '', // 支付方式
			},
			params: {
				year: true,
				month: true,
				day: false,
				hour: false,
				minute: false,
				second: false,
			},
			showw: false,
			list: [
				{
					text: '积分支付',
				},
				{
					text: '微信支付',
				},
			],
			payment: '',
			classification: '', // 0 积分支付 1 微信支付
		};
	},
	onLoad(options) {
		// this.payInfo = uni.getStorageSync('payInfo');
		this.payInfo.porpertyId = options.id;
	},

	methods: {
		async chooseToPay(e) {
			console.log('e: ', e);
			this.classification = e;
			if (e) {
				this.payInfo.payment = e + '';
				this.payment = '微信支付';
			} else {
				this.payInfo.payment = e + '';
				this.payment = '积分支付';
			}
		},
		async options() {
			this.showw = true;
		},
		async confirm(e) {
			this.payInfo.paymentTime = e.year + '-' + e.month;
		},
		click() {
			console.log('111 :>> ', 111);
			this.show = true;
		},
		pay() {
			var that = this;
			if (
				this.payInfo.fullName != '' &&
				this.payInfo.contactDetails != '' &&
				this.payInfo.floor != '' &&
				this.payInfo.unit != '' &&
				this.payInfo.houseNumber != '' &&
				this.payInfo.paymentAmount != '' &&
				this.payInfo.paymentTime != '' &&
				this.payment != ''
			) {
				uni.setStorageSync('payInfo', that.payInfo);
				uni.showModal({
					title: '提示',
					content: '是否确认缴费~~',
					success: function(res) {
						if (res.confirm) {
							// 0 积分支付 1 微信支付
							that.classification ? that.wechatPay() : that.pointsPayment();
						} else if (res.cancel) {
						}
					},
				});

				//新增缴费信息
			} else {
				uni.showModal({
					title: '提示',
					content: '请将信息填写完整~~',
				});
			}
		},
		// 积分支付
		async pointsPayment() {
			var that = this;
			app.globalData.api.savetPropertyPay(that.payInfo).then(ress => {
				if (ress.code == 200) {
					uni.navigateTo({
						url: 'paymentRec',
					});
				}
			});
		},
		// 微信支付
		async wechatPay() {
			app.globalData.api.wxPay(this.payInfo.paymentAmount).then(res => {
				wx.requestPayment({
					timeStamp: res.resultObj.wxPayRequest.timeStamp,
					nonceStr: res.resultObj.wxPayRequest.nonceStr,
					package: res.resultObj.wxPayRequest.packageValue,
					signType: 'MD5',
					paySign: res.resultObj.wxPayRequest.paySign,
					success(res1) {
						setTimeout(() => {
							uni.navigateTo({
								url: 'paymentRec',
							});
						}, 1000);
					},
					fail(res2) {
						console.log('failed', res2);
					},
				});
			});
		},
	},
};
</script>

<style lang="scss">
.content {
	.determine {
		width: 690rpx;
		height: 80rpx;
		background: #f8ce39;
		border-radius: 12rpx;

		font-size: 30rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #333333;
		line-height: 80rpx;
		margin: 60rpx 0;
	}
	.head {
		width: 690rpx;

		background: #ffffff;
		border-radius: 20rpx;
		.personal {
			font-size: 32rpx;
			font-family: PingFang SC;
			font-weight: 500;
			color: #333333;
		}
		input {
			width: 100%;
		}
		.info {
			margin-top: 30rpx;
			text {
				font-size: 28rpx;
				font-family: PingFang SC;
				font-weight: 500;
				color: #333333;
				&::after {
					content: '*';
					color: red;
					margin-left: 5rpx;
					font-size: 28rpx;
				}
			}
			.info_o {
				width: 630rpx;
				height: 70rpx;
				border: 1rpx solid #e6e6e6;
				border-radius: 6rpx;
			}
		}
	}
}
</style>
